package bairui.international.console.web.controller.advance.category;

import com.lianjing.sh.spring.web.controller.enhance.output.bean.*;

/**
 *
 * @see bairui.international.console.web.controller.advance.category.ProductPage_OutputInfo 信息
 *
 */
@SuppressWarnings("serial")
class ProductPage_Output
{

	
	static public class Model
	 extends bairui.international.model.domain.jpa.TB_Product
	{
	
		/**
		 * 构造函数
		 */
			@lombok.Getter @com.fasterxml.jackson.annotation.JsonIgnore
			private bairui.international.model.domain.jpa.TB_Product _origin;
	
		public Model(
			bairui.international.model.domain.jpa.TB_Product bean
		) {
			this._origin = bean;
			if(null != bean){
				this.setId(bean.getId());
				this.setImgUrl(bean.getImgUrl());
				this.setNumber(bean.getNumber());
				this.setName(bean.getName());
				this.setPrice(bean.getPrice());
				this.setShowPrice(bean.getShowPrice());
				this.setExchange(bean.getExchange());
				this.setDivideRate(bean.getDivideRate());
				this.setOrderValue(bean.getOrderValue());
				this.setProductCategory(bean.getProductCategory());
				this.setState(bean.getState());
				this.setProductPropertyItems(bean.getProductPropertyItems());
			}
		}
		
	
		/**
		 * 非继承属性
		 */
	
	
		/**
		 * json忽略注解覆盖继承属性
		 */
		@com.fasterxml.jackson.annotation.JsonIgnore
		public bairui.international.model.domain.jpa.TB_ProductCategory getProductCategory() {
			return super.getProductCategory();
		}
		@com.fasterxml.jackson.annotation.JsonIgnore
		public java.util.List<bairui.international.model.domain.jpa.TB_ProductPropertyItem> getProductPropertyItems() {
			return super.getProductPropertyItems();
		}
	
		/**
		 * 对象转字符串输出
		 */
		public String getProductCategoryToString() {
			bairui.international.model.domain.jpa.TB_ProductCategory it = this.getProductCategory();
			if(null != it){
				return it.toString();
			}
			return null;
		}
		public String getProductPropertyItemsToString() {
			java.util.List<bairui.international.model.domain.jpa.TB_ProductPropertyItem> it = this.getProductPropertyItems();
			if(null != it){
				return it
						.stream()
						.map(bairui.international.model.domain.jpa.TB_ProductPropertyItem::toString)
						.collect(java.util.stream.Collectors.toList())
						.toString();
			}
			return null;
		}
	
		/**
		 * 相关类
		 */
	
	}
	

	/**
	 * ajax 列表输出数据
	 */	
	final static java.util.List<Model> output(
		java.util.List<bairui.international.model.domain.jpa.TB_Product> content
	) {
		java.util.List<Model> newContent = new java.util.ArrayList<>();
		for(bairui.international.model.domain.jpa.TB_Product bean : content){
			newContent.add(new Model(bean));
		}
		return newContent;
	}
	
	/**
	 * ajax 分页输出数据
	 */
	final static org.springframework.data.domain.Page<Model> output(
		org.springframework.data.domain.Page<bairui.international.model.domain.jpa.TB_Product> page
	) throws Exception {
		return page.map(Model::new);
	}
	
	/**
	 * 分页
	 */
	final static org.springframework.data.domain.Pageable page(
		javax.servlet.http.HttpServletRequest request
	){
		// startPage @RequestParam(name="startPage", required=false, defaultValue="0") Integer startPage
		Integer startPage = 0;
		String startPagePara = request.getParameter("startPage");
		if(null != startPagePara){
			startPage = Integer.parseInt(startPagePara);
		}
		// pageSize @RequestParam(name="pageSize", required=false, defaultValue="10") Integer pageSize
		Integer pageSize = 10;
		String pageSizePara = request.getParameter("pageSize");
		if(null != pageSizePara){
			pageSize = Integer.parseInt(pageSizePara);
		}
		//
		return org.springframework.data.domain.PageRequest.of(startPage, pageSize);
	}
	
	
	/**
	 * 排序扩展接口
	 */
	static interface OrderExtends {
		org.springframework.data.domain.Sort gainProductCategory(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainProductPropertyItems(
			org.springframework.data.domain.Sort.Direction direction
		);
		
	
		default org.springframework.data.domain.Sort sort(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> ... sortBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, sortBase);
		}
	
		default com.querydsl.core.types.OrderSpecifier<?> order(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> orderBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.orderTrans(direction, orderBase);
		}
	}
	
	/**
	 * 排序
	 */
	final static org.springframework.data.domain.Sort sort(
		bairui.international.model.domain.jpa.QTB_Product QRoot,
		javax.servlet.http.HttpServletRequest request
		,OrderExtends orderExtends
	){
		/*
		 * 排序属性
		 */
		// orderBy @RequestParam(name="orderBy", required=false, defaultValue="orderValue") String orderBy
		String orderByPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderBy);
		if(null == orderByPara){
			orderByPara = "orderValue";
		}
		// orderWay @RequestParam(name="orderWay", required=false, defaultValue="DESC") OrderWay orderWay
		String orderWayPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderWay);
		if(null == orderWayPara){
			orderWayPara = "DESC";
		}
		org.springframework.data.domain.Sort.Direction direction = org.springframework.data.domain.Sort.Direction.valueOf(orderWayPara);
	
		//
		switch(orderByPara){
			case "imgUrl":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.imgUrl);
			case "number":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.number);
			case "name":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.name);
			case "price":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.price);
			case "showPrice":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.showPrice);
			case "exchange":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.exchange);
			case "divideRate":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.divideRate);
			case "orderValue":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.orderValue);
			case "productCategoryToString":		return orderExtends.gainProductCategory(direction);
			case "state":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.state);
			case "productPropertyItemsToString":		return orderExtends.gainProductPropertyItems(direction);
			default:
				throw new RuntimeException();
		}
	}
	
	
	

}

